@extends('layouts.index')
@section('title',trans('web.course_detail'))
    @section('content')
        <div class="main-container">
            <header class="editorial-header">

                <div class="span14-mobile pixel-pattern editorial-header__leftbox">
                    <div class="pixel-text editorial__fancytext"><span class="pixel-text__text">{{\Illuminate\Support\Carbon::parse($detail->created_at)->day}}</span></div>
                    <div class="editorial-header__leftbox__info editorial-header__leftbox__info--faded">
                            {{trans('datetime.'.\Illuminate\Support\Carbon::parse($detail->created_at)->month)}}
                    </div>
                    <div class="editorial-header__leftbox__info">{{$detail->user->name or ''}}</div>
                </div>
                <div class="span14-mobile editorial-header__rightbox">
                 @can('comment_display')   <div class="course-delete">
                        <button onclick="javascript:location.href='{{route('course_del',['course_id'=>$detail->id])}}'">删除课程</button>
                    </div>
                @endcan
                    <!--正文部分-->
                    <div class="span10 span14-mobile editorial-header__rightbox__container">

                        <h1 class="">{{$detail->title}}</h1>
                        <!--从富文本编辑的文本放在这个地方-->
                        <div>{!! clean($detail->content) !!}</div>
                    </div>

                    <div class="course-comment">

                        <div class="replies panel panel-default list-panel replies-index" id="replies">

                            <div class="panel-heading">
                                <div class="total">@lang('web.comments_num'): <b>{{$detail->comments}}</b> </div>

                              {{--  <div class="order-links">
                                    <a class="btn btn-default btn-sm active popover-with-html" data-content="按照时间排序" href="https://laravel-china.org/articles/6463/recording-the-development-of-a-npm-package-smms?order_by=created_at&amp;#replies" role="button" data-original-title="" title="">时间</a>
                                    <a class="btn btn-default btn-sm  popover-with-html" data-content="按照投票排序" href="https://laravel-china.org/articles/6463/recording-the-development-of-a-npm-package-smms?order_by=vote_count&amp;#replies" role="button" data-original-title="" title="">投票</a>
                                </div>--}}

                            </div>

                            <div class="panel-body">

                                <ul class="list-group row">
                                    @if(count($detail->comment))
                                        @foreach($detail->comment as $v)
                                    <li class="list-group-item media" style="margin-top: 0px;">

                                        <div class="infos">

                                            <div class="media-heading">

                                                <a href="{{--todo:个人详情--}}" title="{{$v->user->name or ''}}" class="remove-padding-left author">
                                                    {{$v->user->name or ''}}
                                                </a>


                                                <span class="introduction">

        </span>

                                                <span class="operate pull-right">


                    <a class="fa fa-reply" href="javascript:void(0)" onclick="replyOne('{{$v->user->name or ''}}',{{$v->user->id or ''}});" title="{{$v->user->name or ''}}"></a>
        </span>
                                                @can('comment_display') <span class="operate pull-right">


                    <a class="fa fa-delete" href="{{route('comment_del',['comment_id'=>$v->id])}}"  title="屏蔽"></a>
        </span>@endcan

                                                <div class="meta">
                                                    <a name="reply33325" id="reply33325" class="anchor" href="#reply33325" aria-hidden="true"></a>


                                                    <span> ⋅  </span>
                                                    <abbr class="timeago popover-with-html" title="" data-content="2017-10-24 13:51:52" data-original-title="2017-10-24 13:51:52">{{$v->created_at}}</abbr>

                                                </div>

                                            </div>

                                            <div class="media-body markdown-reply content-body">
                                                @if($v->replay_user_id!=null)  <p><a href="{{--todo:个人详细资料--}}">{{'@'.$v->replay_user->name }}</a>@endif {{$v->content or ''}}</p>
                                            </div>

                                        </div>

                                    </li>
                                        @endforeach
@else
                                        <div id="replies-empty-block" class="empty-block">@lang('web.no_comments')</div>

                                    @endif

                                </ul>

                                <!-- Pager -->
                                <div class="pull-right" style="padding-right:20px">

                                </div>
                            </div>
                        </div>
                        <div class="reply-box form box-block">
                            <form method="POST" action="{{route('comment_post')}}" accept-charset="UTF-8" id="reply-form">
                                {{csrf_field()}}
                                <div class="form-group">
                                    <textarea class="form-control" rows="5" placeholder="@lang('web.input_comment')" style="overflow: hidden; word-wrap: break-word; resize: horizontal; height: 164px;" id="reply_content" name="content" cols="50"></textarea>
                                </div>
                            <input type="hidden"  id="replay_user_id" name="replay_user_id" value="" >
                                <input type="hidden" id="course_id" name="course_id" value="{{$detail->id}}">
                                <div class="form-group reply-post-submit">
                                    <input class="btn btn-primary " id="reply-create-submit" type="submit" value="回复">
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </header>
        </div>
<script>
    function replyOne(username,user_id){
        replyContent = $("#reply_content");
        $("#replay_user_id").val(user_id);
        oldContent = replyContent.val();
        prefix = "@" + username + " ";
        newContent = ''
        if(oldContent.length > 0){
            if (oldContent != prefix) {
                newContent = oldContent + "\n" + prefix;
            }
        } else {
            newContent = prefix
        }
        replyContent.focus();
        replyContent.val('');
        replyContent.attr('placeholder',newContent);
        moveEnd($("#reply_content"));
    }
</script>
        @endsection